package com.ruoyi.management.pojo.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;


@Data
@NoArgsConstructor
public class WebSocketResponse<T> {
    private String code;     // 状态码（如：200/400/500）
    private String message;  // 消息描述
    private T data;          // 业务数据
    private Instant timestamp = Instant.now(); // 时间戳

    // 成功响应快捷方法
    public static <T> WebSocketResponse<T> success(T data) {
        return new WebSocketResponse<>("200", "Success", data, Instant.now());
    }

    // 错误响应快捷方法
    public static <T> WebSocketResponse<T> error(String code, String message) {
        return new WebSocketResponse<>(code, message, null, Instant.now());
    }

    // 构造方法支持泛型 T
    public WebSocketResponse(String code, String message, T data) {
        this(code, message, data, Instant.now());
    }

    // 全参构造方法
    public WebSocketResponse(String code, String message, T data, Instant timestamp) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = timestamp;
    }
}